package com.xiaoxi.proxymode;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.proxymode
 * @ClassName Printer
 * @Description TODO
 * @Date 2023/4/6 21:52
 * @Version 1.0
 */
public class Printer implements Printable {

    private String name;

    public Printer() {
        heavyJob("正在生成print的实例");
    }

    public Printer(String name) {
        this.name = name;
        heavyJob("正在生成print的实例 (" + name + ")");
    }

    @Override
    public void setPrinterName(String name) {
        this.name = name;
    }

    @Override
    public String getPrinterName() {
        return name;
    }

    @Override
    public void print(String str) {
        System.out.println("========== " + name + " =======");
        System.out.println(str);
    }

    private void heavyJob(String msg) {
        System.out.println(msg);
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.print(".");
        }
        System.out.println("结束");
    }

}
